function loadXML( obj, node )
%load data from Project XML file

% This file is part of CISNE.
%
%     CISNE is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     any later version.
%
%     CISNE is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with CISNE.  If not, see <http://www.gnu.org/licenses/>.

% Copyright 2013. Jose Maria Garcia-Valdecasas Bernal

warn=false;
%node is the SETUP node. ChildNodes are the Properties
childNodes=node.getChildNodes();
k=0; %will be used to read the property table.
for j=0:childNodes.getLength()-1
    %get one property
    child=childNodes.item(j);
    %retrieve name of the property
    name=char(child.getNodeName());
    name=regexprep(name,'_',' ');
    %retrieve the value of the property
    value=char(child.getTextContent());
    kind=char(child.getAttribute('kind'));
    value=txt2data(value,kind);
    
    %in theory, SetupWidget is static, no new settings should be added and
    %keep the same XML version. This should be a simple test to verify it
    %and skip not matching settings. -> display warning if happens.
    while (obj.m_gridmodel.isCategoryRow(k))
        k=k+1; %skip category rows
    end
    
    prop=obj.m_gridmodel.getPropertyAt(k);
    k=k+1;
    propName=char(prop.getName());
    if strcmp(propName,name)
        prop.setValue(value);
    else
        warn=true;
    end    
end

obj.m_gridmodel.refresh();
obj.m_gridmodel.expandAll();
obj.m_gridmodel.refresh();

if warn
    warndlg(['Some settings mismatch between the project file'...
        'and CISNE setup widget. Verify all settings to avoid errors']);
end

end

function data=txt2data(text,kind)

switch kind
    case 'int'
        data=str2double(text);
    case 'num'
        data=str2double(text);
    case 'bool'
        if strcmp(text,'false')
            data=false;
        else
            data=true;
        end
    otherwise
        data=text;        
end
end




